<?php
/**
 * 验证码封装
 * Date: 2025/08/31
 */

namespace App\libraries\Captcha;

use Gregwar\Captcha\CaptchaBuilder;
use Gregwar\Captcha\PhraseBuilder;

class VerifyCode
{
    /**
     * 获取验证码
     * @date 2025/08/31
     * @return array
     */
    public function getVerifyCode()
    {
        //使用PhraseBuilder控制验证码位数
        $captcha = new CaptchaBuilder(null, new PhraseBuilder(4));
        $captcha->setMaxAngle(0)->setMaxFrontLines(0)->build();
        return [
            'token' => md5(uniqid() . rand(10000, 99999)),
            'code' => strtolower($captcha->getPhrase()),
            'base64' => $captcha->inline()
        ];
    }
}
